<%@ page import="java.util.ArrayList" %>
<%@ page import="com.example.oa.Employee" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.oa.Employee"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>admin page</title>
  <script>
    function del() {
      return confirm(com.example.oa.Employee"delete this record?");
    }
  </script>
</head>
<body>
<h1>admin page</h1>
<h3>Welcome: ${sessionScope.name}</h3>
<a href="add.jsp">Add employee</a>
<hr>
<table border="1">
  <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>AGE</th>
    <th>GENDER</th>
    <th colspan="3">OPERATIONS</th>
  </tr>

  <%
    ArrayList<Employee> employees = (ArrayList<Employee>)session.getAttribute("employees");

    for (Employee employee : employees) {
      out.print("<tr>");
      out.print("<td>" + employee.getId() + "</td>");
      out.print("<td>" + employee.getName() + "</td>");
      out.print("<td>" + employee.getAge() + "</td>");
      out.print("<td>" + employee.getGender() + "</td>");
      out.print("<td><a href='/employee?action=findById&id=" + employee.getId() + "'>EDIT</a></td>");
      out.print("<td><a href='/employee?action=removeById&id=" + employee.getId() + "' onclick='return del()'>REMOVE</a></td>");
      out.print("<td><a href='/employee?action=detail&id=" + employee.getId() + "'>DETAIL</a></td>");
      out.print("</tr>");
    }
  %>
</table>

<hr>
<table border="1">
  <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>AGE</th>
    <th>GENDER</th>
    <th colspan="3">OPERATIONS</th>
  </tr>
<c:forEach var="employee" items="${sessionScope.employees}">
  <tr>
    <td>${employee.id}</td>
    <td>${employee.name}</td>
    <td>${employee.age}</td>
    <td>${employee.gender}</td>
    <td><a href="/employee?action=findById&id=${employee.id}">EDIT</a> </td>
    <td><a href="/employee?action=removeById&id=${employee.id}"onclick="return del()">REMOVE</a> </td>
    <td><a href="/employee?action=detail&id=${employee.id}">DETAIL</a> </td>
  </tr>
</c:forEach>
</table>
<hr>


<a href="/employee?action=sign_out">Sign out</a>
</body>
</html>